using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GZ.DB.Entity.wcs_hy;
using GZ.DB.IRepository.wcs_hy;
using GZ.DB.Repository.wcs_hy;
using GZ.Common.Data;

namespace GZ.Projects.WCS_YB
{
    /// <summary>
    /// 任务确认反馈结果
    /// </summary>
    public class TaskConfirmResult
    {
        /// <summary>
        /// 是否成功执行
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 执行结果消息
        /// </summary>
        public string Message { get; set; }

        public TaskConfirmResult(bool isSuccess, string message)
        {
            IsSuccess = isSuccess;
            Message = message;
        }
    }

    /// <summary>
    /// 任务确认反馈辅助类
    /// </summary>
    public class TaskConfirmHelper
    {
        private Conn Conn = new Conn();


        /// <summary>
        /// 设置LAST反馈
        /// </summary>
        /// <param name="num">堆垛机编号</param>
        /// <returns>处理结果</returns>
        public TaskConfirmResult SetLastFeedback(string num)
        {
            string suffixName = $"TC{num}";
            string msg = $"\r\n[堆垛机任务完成反馈LAST更新[{suffixName}]]：Start{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            DateTime startTime = DateTime.Now;
            bool result = new StackerSendToRedis().SendLast_SingleStation(num, out string eMsg);
            if (!result)
            {
                msg += $"\r\n\t[堆垛机完成反馈LAST更新异常]：指令清除结果失败{{DateTime.Now:yyyy/MM/dd HH:mm:ss}}\" + eMsg;";
            }
            msg += $"\r\n\t[堆垛机任务完成反馈LAST更新[{suffixName}]]：End{DateTime.Now:yyyy/MM/dd HH:mm:ss}，耗时：{(DateTime.Now - startTime).TotalMilliseconds}ms，结果：{result}";
            return new TaskConfirmResult(result, msg);
        }

        /// <summary>
        /// 交互反馈
        /// </summary>
        /// <param name="num">堆垛机编号</param>
        /// <returns>处理结果</returns>
        public TaskConfirmResult InteractionFeedback(string num)
        {
            //单工位堆垛机  任务完成反馈
            //
            //plc taskstatus1=3 正常完成 wcs ConfirmSignal1 3任务完成确认
            //plc 5强制完成  wcs 10 强制完成
            //plc 6取消任务  wcs  8 任务删除
            string suffixName = $"TC{num}";
            string msg = $"\r\n[堆垛机任务完成反馈及更新[{suffixName}]]：Start{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            DateTime startTime = DateTime.Now;
            bool isSuccess = true;
            try
            {
                //查找是否存在已下发的任务，堆垛机接收指令的托盘号是否正确
                string plcTaskId1Value1 = Conn.YBRedis.GetValue($"{suffixName}.plc_taskId1"); //堆垛机工位1条码
                //StackerTaskEntity stackerTask = new StackerTaskEntity();
                IStackerTaskRepository stackerRepo = new StackerTaskRepository(); //处理数据库
                //MainMissionEntity mainEntity  = new MainMissionEntity();
                IMainMissionRepository mainMissionRepo = new MainMissionRepository();

                DBOpeation dbOpeation = new DBOpeation();

                StackerTaskEntity stackerTask = stackerRepo
                    .FindList(t =>
                        (t.TaskState == "Send" || t.TaskState == "Doing") && t.DeviceNo == suffixName &&
                        t.DeviceTaskNo == plcTaskId1Value1).OrderByDescending(t => t.CreateTime).LastOrDefault();
                MainMissionEntity mainEntity = mainMissionRepo
                    .FindList(t =>
                        (t.MissionState == "Send" || t.MissionState == "Doing") &&
                        t.device_task_no == stackerTask.DeviceTaskNo && t.tray_code == stackerTask.TrayCode)
                    .OrderByDescending(t => t.CreateTime).LastOrDefault();

                //修改数据库 状态为doing
                if (stackerTask != null && mainEntity != null)
                {
                    stackerTask.TaskState = "Doing";
                    stackerTask.TaskStartTime = DateTime.Now;
                    stackerTask.LastUpdatedTime = DateTime.Now;

                    mainEntity.MissionState = "Doing";
                    mainEntity.MissionStartTime = DateTime.Now;
                    mainEntity.LastUpdatedTime = DateTime.Now;
                    bool result = dbOpeation.UpdateStackerAndMainTask(stackerTask, mainEntity, out string err);
                    if (result)
                    {
                        msg += $"\r\n\t更新任务成功{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                        bool clearTaskResult = new StackerSendToRedis().ClearTask_SingleStation(num, "0", "1", out string ermsg);
                        msg += $"\r\n\t下发点位清零结果:{clearTaskResult}{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                    }
                    else
                    {
                        msg += $"\r\n\t更新任务失败，{err}{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                        isSuccess = false;
                    }
                }
                else
                {
                    msg += $"\r\n\t[堆垛机信息异常]：堆垛机工位1的任务号无法查询到任务信息";
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                msg += $"\r\n\t[Error]{ex}";
                isSuccess = false;
            }

            msg += $"\r\n\t[EndTime]{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            msg += $"\r\n\t[SpanTime]{(int)(DateTime.Now - startTime).TotalMilliseconds}" + "ms";
            msg += $"\r\n[堆垛机任务交互反馈[{suffixName}]]End";
            return new TaskConfirmResult(isSuccess, msg);
        }

        /// <summary>
        /// 正常完成反馈
        /// </summary>
        /// <param name="num">堆垛机编号</param>
        /// <returns>处理结果</returns>
        public TaskConfirmResult NormalFinishFeedback(string num)
        {
            //单工位堆垛机  任务完成反馈
            //
            //plc taskstatus1=3 正常完成 wcs ConfirmSignal1 3任务完成确认
            //plc 5强制完成  wcs 10 强制完成
            //plc 6取消任务  wcs  8 任务删除
            string suffixName = $"TC{num}";
            string msg = $"\r\n[[{suffixName}]任务正常完成处理]：Start{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            DateTime startTime = DateTime.Now;
            bool isSuccess = true;
            try
            {
                //查找是否存在已下发的任务，堆垛机接收指令的托盘号是否正确
                string plcTaskId1Value1 = Conn.YBRedis.GetValue($"{suffixName}.plc_taskId1"); //堆垛机工位1条码
                string memDeviceTaskNo = Conn.YBRedis.GetValue($"MEM.{suffixName}_DeviceTaskNo"); //mem记录的设备任务号
                string memCont = Conn.YBRedis.GetValue($"MEM.{suffixName}_Cont"); //mem记录的任务条码
                IStackerTaskRepository stackerRepo = new StackerTaskRepository(); //处理数据库
                //MainMissionEntity mainEntity  = new MainMissionEntity();
                IMainMissionRepository mainMissionRepo = new MainMissionRepository();

                DBOpeation dbOpeation = new DBOpeation();

                if (memCont == "0" && memDeviceTaskNo == "0" )
                {
                    msg += $"\r\n\t[堆垛机信息完成异常]：堆垛机工位1的任务号无法查询到任务信息";
                    isSuccess = false;
                    bool taskResult = new StackerSendToRedis().ClearTask_SingleStation(num, "0", "3", out string eMsg);
                    if (!taskResult)
                    {
                        msg += $"\r\n\t[堆垛机信息完成异常]：指令清除结果失败{{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}}\" + eMsg;";
                    }
                }

                StackerTaskEntity stackerTask = stackerRepo
                    .FindList(t =>
                        (t.TaskState == "Send" || t.TaskState == "Doing") && t.DeviceNo == suffixName &&
                        t.DeviceTaskNo == memDeviceTaskNo).OrderByDescending(t => t.CreateTime).LastOrDefault();
                //如果查找出来的不是空 记一下日志 并且输出
                if (stackerTask != null)
                {
                    //任务完成，还要把变量组的mem清除一下
                    //三个参数，哪台堆垛机 命令类型 确认信号
                    bool taskResult = new StackerSendToRedis().ClearTask_SingleStation(num, "0", "3", out string eMsg);
                    if (!taskResult)
                    {
                        msg += $"\r\n\t[堆垛机信息完成异常]：指令清除结果失败{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}" + eMsg;
                        isSuccess = false;
                    }

                    //如果是入库和移库任务
                    if (stackerTask.TaskType == "ST_In" || stackerTask.TaskType == "ST_Move")
                    {
                        MainMissionEntity mainEntity = mainMissionRepo
                            .FindList(t =>
                                (t.MissionState == "Send" || t.MissionState == "Doing") &&
                                t.device_task_no == stackerTask.DeviceTaskNo &&
                                t.tray_code == stackerTask.TrayCode).OrderByDescending(t => t.CreateTime)
                            .LastOrDefault();
                        if (mainEntity != null)
                        {
                            //修改数据库 状态为完成
                            stackerTask.TaskState = "Finish";
                            stackerTask.TaskEndTime = DateTime.Now;
                            stackerTask.LastUpdatedTime = DateTime.Now;

                            mainEntity.MissionState = "Finish";
                            mainEntity.MissionEndTime = DateTime.Now;
                            mainEntity.LastUpdatedTime = DateTime.Now;
                            //todo 接口上报任务状态
                            SystemSynchronizationEntity systemSynchronization = new SystemSynchronizationEntity();
                            systemSynchronization.syn_direction = 2;
                            systemSynchronization.syn_status = 0;
                            systemSynchronization.ope_type = "2";  //任务完成
                            systemSynchronization.order_no = mainEntity.order_no;
                            systemSynchronization.task_no = mainEntity.task_no;
                            systemSynchronization.ope_time = DateTime.Now;
                            systemSynchronization.cur_pos = mainEntity.end_position;

                            bool resultMs = dbOpeation.UpdateMainAndStackInsertSysTask(mainEntity, stackerTask,
                                systemSynchronization, out string err);
                            if (resultMs)
                            {
                                StackMemTaskInfo("0", "0", "0", "0", num);
                                msg += $"\r\n\t[任务完成信号回复及清除MEM记录值]";
                            }
                            else
                            {
                                msg += $"\r\n\t[堆垛机信息完成异常]：数据库更新失败{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}" + err;
                            }
                        }
                        else
                        {
                            msg += $"\r\n\t[堆垛机信息完成异常]：主任务号{stackerTask.DeviceTaskNo}无法查询到任务信息";
                        }
                    }
                    else if (stackerTask.TaskType == "ST_Out")
                    {
                        //出库任务
                        MainMissionEntity mainEntity = mainMissionRepo
                            .FindList(t =>
                                (t.MissionState == "Send" || t.MissionState == "Doing") &&
                                t.device_task_no == stackerTask.DeviceTaskNo &&
                                t.tray_code == stackerTask.TrayCode).OrderByDescending(t => t.CreateTime)
                            .LastOrDefault();
                        if (mainEntity != null)
                        {
                            msg += $"\r\n\t[出库任务]堆垛机任务完成信号回复及清除MEM记录值";
                            msg += $"\r\n\t[DB查询]查找任务结束，设备任务号{stackerTask.DeviceTaskNo},准备更新任务";
                            //修改数据库 状态为完成
                            mainEntity.MissionState = "Doing";
                            mainEntity.InteStationNo = stackerTask.ToLocalNo;
                            mainEntity.LastUpdatedTime = DateTime.Now;

                            stackerTask.TaskState = "Finish";
                            stackerTask.TaskEndTime = DateTime.Now;
                            stackerTask.LastUpdatedTime = DateTime.Now;

                            bool resultMt =
                                dbOpeation.UpdateMainAndUpdateStack(mainEntity, stackerTask, out string err1);
                            if (resultMt)
                            {
                                StackMemTaskInfo("0", "0", "0", "0", num);
                                msg += $"\r\n\t[任务完成信号回复及清除MEM记录值]";
                            }
                            else
                            {
                                msg += $"\r\n\t[堆垛机信息完成异常]：数据库更新失败{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                            }
                        }
                        else
                        {
                            msg +=
                                $"\r\n\t[堆垛机信息完成异常]：未查询到主任务信息关于{stackerTask.DeviceTaskNo}的设备任务号{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                        }
                    }
                }
                else
                {
                    msg += $"\r\n\t[堆垛机信息完成异常]：堆垛机任务号{plcTaskId1Value1}无法查询到任务信息,此时wcs记录的mem条码为{memCont}，任务号为{memDeviceTaskNo}";
                }
            }
            catch (Exception ex)
            {
                msg += $"\r\n\t[Error]{ex}";
                isSuccess = false;
            }

            msg += $"\r\n\t[EndTime]{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            msg += $"\r\n\t[SpanTime]{(int)(DateTime.Now - startTime).TotalMilliseconds}" + "ms";
            msg += $"\r\n[{suffixName}]任务正常完成]End";
            return new TaskConfirmResult(isSuccess, msg);
        }

        /// <summary>
        /// 强制完成反馈
        /// </summary>
        /// <param name="num">堆垛机编号</param>
        /// <returns>处理结果</returns>
        public TaskConfirmResult ForceFinishFeedback(string num)
        {
            //单工位堆垛机  任务完成反馈
            //
            //plc taskstatus1=3 正常完成 wcs ConfirmSignal1 3任务完成确认
            //plc 5强制完成  wcs 10 强制完成
            //plc 6取消任务  wcs  8 任务删除
            string suffixName = $"TC{num}";
            string msg = $"\r\n[[{suffixName}]任务正常完成处理]：Start{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            DateTime startTime = DateTime.Now;
            bool isSuccess = true;
            try
            {
                //查找是否存在已下发的任务，堆垛机接收指令的托盘号是否正确
                string plcTaskId1Value1 = Conn.YBRedis.GetValue($"{suffixName}.plc_taskId1"); //堆垛机工位1条码
                string memCont = Conn.YBRedis.GetValue($"MEM.{suffixName}_Cont"); //mem记录的任务条码
                //StackerTaskEntity stackerTask = new StackerTaskEntity();
                IStackerTaskRepository stackerRepo = new StackerTaskRepository(); //处理数据库
                //MainMissionEntity mainEntity = new MainMissionEntity();
                IMainMissionRepository mainMissionRepo = new MainMissionRepository();

                DBOpeation dbOpeation = new DBOpeation();

                if (memCont == "0")
                {
                    memCont = plcTaskId1Value1;
                }

                var stackerTask = stackerRepo
                    .FindList(t =>
                        (t.TaskState == "Send" || t.TaskState == "Doing") && t.DeviceNo == suffixName &&
                        t.TrayCode == memCont).OrderByDescending(t => t.CreateTime).LastOrDefault();
                //如果查找出来的不是空 记一下日志 并且输出
                if (stackerTask != null)
                {
                    //任务完成，还要把变量组的mem清除一下
                    msg += $"\r\n\t查找任务结束，更新任务{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                    //修改数据库 状态为Cancel
                    stackerTask.TaskState = "Finish";
                    stackerTask.TaskEndTime = DateTime.Now;
                    stackerTask.LastUpdatedTime = DateTime.Now;

                    bool result = dbOpeation.UpdateStackerTask(stackerTask, out string error);

                    //主任务如果是入库的话，不能完成
                    if (stackerTask.TaskType == "ST_In")
                    {
                       var mainEntity = mainMissionRepo
                            .FindList(t =>
                                (t.MissionState == "Send" || t.MissionState == "Doing") &&
                                t.task_no == stackerTask.TaskNo && t.tray_code == stackerTask.TrayCode)
                            .OrderByDescending(t => t.CreateTime).LastOrDefault();
                        if (mainEntity != null)
                        {
                            mainEntity.MissionState = "Finish";
                            mainEntity.MissionEndTime = DateTime.Now;
                            mainEntity.LastUpdatedTime = DateTime.Now;
                            //todo 接口
                            SystemSynchronizationEntity systemSynchronization = new SystemSynchronizationEntity();
                            systemSynchronization.syn_direction = 2;
                            systemSynchronization.syn_status = 0;
                            systemSynchronization.ope_type = "2";
                            systemSynchronization.order_no = mainEntity.order_no;
                            systemSynchronization.task_no = mainEntity.task_no;
                            systemSynchronization.task_no = mainEntity.task_no;
                            systemSynchronization.cur_pos = mainEntity.end_position;
                            
                            bool resultMs =
                                dbOpeation.UpdateMainAndInsertSyn(mainEntity, systemSynchronization, out string err);
                        }
                    }

                    //任务完成，还要把变量组的mem清除一下
                    //三个参数，哪台堆垛机 命令类型 确认信号
                    bool taskResult = new StackerSendToRedis().ClearTask_SingleStation(num, "0", "5", out string ermsg);
                    StackMemTaskInfo("0", "0", "0", "0", num);
                    msg += $"\r\n\t[任务完成信号回复及清除MEM记录值]";
                }
                else
                {
                    bool taskFinishResult2 = new StackerSendToRedis().ClearTask_SingleStation(num, "0", "5", out string errormsg);
                    StackMemTaskInfo("0", "0", "0", "0", num);
                    msg += $"\r\n\t获取堆垛机任务异常，信号清除回复结果：{taskFinishResult2}{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                msg += $"\r\n\t[Error]{ex}";
                isSuccess = false;
            }

            msg += $"\r\n\t[EndTime]{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            msg += $"\r\n\t[SpanTime]{(int)(DateTime.Now - startTime).TotalMilliseconds}" + "ms";
            msg += $"\r\n[{suffixName}]任务正常完成]End";
            return new TaskConfirmResult(isSuccess, msg);
        }

        /// <summary>
        /// 取消任务反馈
        /// </summary>
        /// <param name="num">堆垛机编号</param>
        /// <returns>处理结果</returns>
        public TaskConfirmResult CancelFeedback(string num)
        {
            //单工位堆垛机  任务完成反馈
//
//plc taskstatus1=3 正常完成 wcs ConfirmSignal1 3任务完成确认  
//plc 5强制完成  wcs 10 强制完成
//plc 6取消任务  wcs  8 任务删除
            string suffixName = $"TC{num}";
            string msg = $"\r\n[[{suffixName}]取消任务处理]：Start{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            DateTime startTime = DateTime.Now;
            bool isSuccess = true;
            try
            {
//查找是否存在已下发的任务，堆垛机接收指令的托盘号是否正确
                string plcTaskId1Value1 = Conn.YBRedis.GetValue($"{suffixName}.plc_taskId1"); //堆垛机工位1条码
                string memCont = Conn.YBRedis.GetValue($"MEM.{suffixName}_Cont"); //mem记录的任务条码
                //StackerTaskEntity stackerTask = new StackerTaskEntity();
                IStackerTaskRepository stackerRepo = new StackerTaskRepository(); //处理数据库
                //MainMissionEntity mainEntity = new MainMissionEntity();
                IMainMissionRepository mainMissionRepo = new MainMissionRepository();

                DBOpeation dbOpeation = new DBOpeation();
                var stackerTask = stackerRepo
                    .FindList(t =>
                        (t.TaskState == "Send" || t.TaskState == "Doing") && t.DeviceNo == suffixName &&
                        t.TrayCode == memCont).OrderByDescending(t => t.CreateTime).LastOrDefault();
                //如果查找出来的不是空 记一下日志 并且输出
                if (stackerTask != null)
                {
                    
                    msg += $"\r\n\t取消任务成功，更新任务{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                    //修改数据库 状态为Cancel
                    stackerTask.TaskState = "Cancel";
                    stackerTask.TaskEndTime = DateTime.Now;
                    stackerTask.LastUpdatedTime = DateTime.Now;

                    bool result = dbOpeation.UpdateStackerTask(stackerTask, out string error);

                    //主任务也要取消
                   var mainEntity = mainMissionRepo
                        .FindList(t =>
                            (t.MissionState == "Create" || t.MissionState == "Send" || t.MissionState == "Doing") &&
                            t.task_no == stackerTask.TaskNo && t.tray_code == stackerTask.TrayCode)
                        .OrderByDescending(t => t.CreateTime).LastOrDefault();
                    if (mainEntity != null)
                    {
                        mainEntity.MissionState = "Cancel";
                        mainEntity.MissionEndTime = DateTime.Now;
                        mainEntity.LastUpdatedTime = DateTime.Now;
                        //接口
                        SystemSynchronizationEntity systemSynchronization = new SystemSynchronizationEntity();
                        systemSynchronization.syn_direction = 1;
                        systemSynchronization.syn_status = 0;
                        systemSynchronization.ope_type = "";
                        systemSynchronization.order_no = mainEntity.order_no;
                        systemSynchronization.task_no = mainEntity.task_no;
                        systemSynchronization.ope_time = DateTime.Now;
                        systemSynchronization.ope_type = "CF";

                        bool resultMs =
                            dbOpeation.UpdateMainAndInsertSyn(mainEntity, systemSynchronization, out string err);

                        //任务都发送取消成功，还要把变量组的mem清除一下
                        //三个参数，哪台堆垛机 命令类型 确认信号
                        bool clearTaskResult = new StackerSendToRedis().ClearTask_SingleStation(num, "12", "8", out string ermsg);
                        StackMemTaskInfo("0", "0", "0", "0", num);
                    }
                    else
                    {
                        msg += $"\r\n\t获取主任务异常，上报接口失败{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                        isSuccess = false;
                    }
                }
                else
                {
                    msg += $"\r\n\t获取堆垛机任务异常，请检查状态或者条码{DateTime.Now:yyyy/MM/dd HH:mm:ss:fff}";
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                msg += $"\r\n\t[Error]{ex}";
                isSuccess = false;
            }

            msg += $"\r\n\t[EndTime]{DateTime.Now:yyyy/MM/dd HH:mm:ss}";
            msg += $"\r\n\t[SpanTime]{(int)(DateTime.Now - startTime).TotalMilliseconds}" + "ms";
            msg += $"\r\n[{suffixName}]取消任务结束]End";
            return new TaskConfirmResult(isSuccess, msg);
        }

        /// <summary>
        /// 堆垛机内存任务记录
        /// </summary>
        /// <param name="deviceTaskNo">设备任务编号</param>
        /// <param name="contNum">托盘编码</param>
        /// <param name="curNum">当前位置</param>
        /// <param name="toNum">目标位置</param>
        /// <param name="num">堆垛机编号</param>
        /// <returns>是否成功</returns>
        public bool StackMemTaskInfo(string deviceTaskNo, string contNum, string curNum, string toNum, string num)
        {
            try
            {
                string setQueue = $"MEMQueue";
                string groupName = $"MEM.TC{num}_INFO";

                GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity
                {
                    groupName = groupName,
                    queueStatus = 1,
                    queueTime = DateTime.Now,
                    writeList = new List<GZ.Modular.Redis.ParamData>
                    {
                        new GZ.Modular.Redis.ParamData
                        {
                            paramName = $"MEM.TC{num}_DeviceTaskNo",
                            paramValue = deviceTaskNo
                        },
                        new GZ.Modular.Redis.ParamData
                        {
                            paramName = $"MEM.TC{num}_ContNo",
                            paramValue = contNum
                        },
                        new GZ.Modular.Redis.ParamData
                        {
                            paramName = $"MEM.TC{num}_CurPos",
                            paramValue = curNum
                        },
                        new GZ.Modular.Redis.ParamData
                        {
                            paramName = $"MEM.TC{num}_ToPos",
                            paramValue = toNum
                        }
                    }
                };
                bool result = Conn.YBRedis.SetQueue(group, setQueue, "", "");
                return result;
            }
            catch (Exception e)
            {
                Conn.YBLog.Error(1, $"[堆垛机MEM记录失败[TC{num}]]", 1, e.ToString());
                return false;
            }
        }
    }
}